home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / duplicate_dir < prev    next >
Encoding:
Korn shell script  |  1995-03-24  |  1.8 KB  |  79 lines

  1. #! /bin/ksh
  2. USAGE='USAGE: duplicate_dir DIR_PATH MOUNT_PATH MAP_TO
  3.     For every file in directory DIR_PATH, create a symbolic link to
  4.     it by the same name in the current directory.  If the link is
  5.     below MOUNT_PATH, replace it with a linke with MOUNT_PATH
  6.     replace by MAP_TO
  7. '  
  8. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  9.  
  10. # define std functions
  11.  
  12.    ISOFS_UTIL_DIR="${ISOFS_UTIL_DIR:-/usr/src/linux/fs/isofs/Utils}"
  13.    . "$ISOFS_UTIL_DIR/ksh_fns"
  14.  
  15.  
  16. # Process parameters
  17.  
  18.    if [ $# -ne 3 ]
  19.    then
  20.       echo "$USAGE" >&2
  21.       echo "3 arguments required.  $# given." >&2
  22.       exit 1
  23.    fi
  24.    if [ ! -d "$1" ]
  25.    then
  26.       echo "$1 is not a directory"
  27.    fi
  28.    DIR_ARG="$1"; shift
  29.    if [ ! -d "$1" ]
  30.    then
  31.       echo "$1 is not a directory"
  32.    fi
  33.    MOUNT_PATH="$1"; shift
  34.    if [ ! -d "$1" ]
  35.    then
  36.       echo "$1 is not a directory"
  37.    fi
  38.    MAP_TO="$1"; shift
  39.  
  40. # Set DIR_PATH to hard path
  41.  
  42.    set -P # print absolut hw path
  43.    HERE="$PWD"
  44.    check_cmd 2 cd "$DIR_ARG"
  45.    DIR_PATH="$PWD"
  46.    check_cmd 3 cd "$HERE"
  47.  
  48. # Do it
  49.  
  50.    PREFIX="${MAP_TO%/}/"
  51.    (cd "$DIR_PATH"; ls -a -1) | while read FILE
  52.    do
  53.       if [ "$FILE" != '.' -a "$FILE" != '..' ]
  54.       then
  55.      DEST_FILE="$(follow_link "${DIR_PATH}/${FILE}")"
  56.      if [ "$DEST_FILE" != "${DEST_FILE#${MOUNT_PATH}}" ]
  57.      then
  58.         # Use equivalent path
  59.         DEST_FILE="${DEST_FILE#${MOUNT_PATH}/}"
  60.         DEST_FILE="${PREFIX}$DEST_FILE"
  61.      fi
  62.      ## echo "HERE is $HERE"
  63.      ## echo "DEST_FILE is $DEST_FILE"
  64.      ## echo "FILE is $FILE"
  65.      ## echo "PWD is $PWD"
  66.      if [ "$DEST_FILE" = "$HERE/$FILE" ]
  67.      then
  68.         ln -s "$DIR_PATH/$FILE" "$FILE"
  69.      else
  70.         # Use relative path if possible
  71.         ## echo "HERE is $HERE"
  72.         ## echo "DEST_FILE is $DEST_FILE"
  73.         DEST_FILE="${DEST_FILE#${HERE}/}"
  74.         ## echo ln -s "$DEST_FILE" "${FILE}"
  75.         ln -s "$DEST_FILE" "${FILE}"
  76.      fi
  77.       fi
  78.    done
  79.